#pragma once

#pragma comment(lib,"MD2Model")
#pragma comment(lib,"fmodex_vc")
#pragma comment(lib,"fmodexL_vc")

#include "cScene.h"
#include "cData.h"
#include "cPlayer.h"
#include "cEnemy.h"
#include "cShader.h"
#include "cBoundingBox.h"
#include "cLight.h"
#include "cCamera.h"
#include "Audio.h"
#include "cBoira.h"


#define SCREEN_WIDTH	800
#define SCREEN_HEIGHT	600
#define PLAYER_STEP		0.06
#define PLAYER_ROTATE	0.06
#define PLAYER_ROTATE_SHORT	0.0007
#define PLAYER_STEP_NEXT 0.01
#define NUM_OBJECTS	6
#define NUM_ENEMIES1	5
#define NUM_ENEMIES2	2

class cGame
{
public:
	cGame(void);
	virtual ~cGame(void);

	bool Init();
	bool Loop();
	void Finalize();

	//Input
	void ReadKeyboard(unsigned char key, int x, int y, bool press);
	void ReadMouse(int button, int state, int x, int y);
	//Process
	bool Process();
	//Output
	void Render();
	void onMouseMove(int x, int y);
	void UpdatePositions();
	void UpdateEnemy1Position();
	void UpdateEnemy2Position();
	bool LoadModels();
	void LoadModelsCoords();
	bool LoadTextures();
	void InitFBO();
	void ShowTexture();
	void initAtributs();
	void initShaders();
	void ReadInputs();
	void PlayerAttack();
	void LoadLevel();
	void EnemyAttack(int id, int type);
	void LoadEnemies();

	/*
		type = 1	tecla = w	tecla = s
		type = 2	tecla = e	tecla = q
	*/
	bool colisionaModelEstatic(GLfloat x, GLfloat z);
	void RenderMessages();

	void RenderInterface();

	void updateBoundingBoxPlayer();

	cBoundingBox GetBoxPlayer1();
	cBoundingBox GetBoxEnemy1();

	bool Enemy1Collides(int id, float oldX, float oldZ);
	bool Enemy2Collides(int id);

	void output(int x, int y, float r, float g, float b, LPVOID font, char *string);

	//Audio
	Audio *sounds;

private:
	unsigned char keys[256];
	unsigned char mouse[4];
	cScene Scene;
	cData Data;
	cMD2Model models[NUM_OBJECTS];
	GLfloat mCoordsX[NUM_OBJECTS];
	GLfloat mCoordsZ[NUM_OBJECTS];
	GLfloat mCoordsY[NUM_OBJECTS];

	cBoundingBox BoxsModels[NUM_OBJECTS];

	int idCam;
	GLfloat x, y, z;
	GLfloat incr_steps;
	GLfloat alpha;
	GLfloat alpharad;
	GLfloat beta;
	int mouseX;
	int mouseY;

	
	//System* fmodSystem;



	char* pathVert; 
	char* pathFrag;

	bool boundingBox;
	
	cPlayer player1;
	bool calculatedBox1;
	cBoundingBox BoxPlayer1;

	cEnemy enemy1;
	cEnemy enemies1 [NUM_ENEMIES1];
	cEnemy enemies2 [NUM_ENEMIES2];
	bool calculatedBox2;
	cBoundingBox BoxEnemy1;


	cShader s1;
	cShader s2;
	cShader s3;
	cLight llum;
	cCamera cam;
	cBoira boira;

	bool shader;
	int shaderID;
	
	GLuint fbo;     // Frame Buffer Object
	GLuint fboTexture;  // Textura para FBO
	GLuint fboDepth;    // Depth buffer para el FBO
	int wndWidth, wndHeight;

	//GLfloat auxMaxXPlayer1, auxMaxZPlayer1;

	int ticks_inici;
	bool playingSound1;
	bool playingSound2;


	int id_DL;
	int id_DL2;
	int id_DL3;
	int id_DL4;

	void LoadLife1();
	void LoadLife2();
	void LoadLife3();
	void LoadCaraEnemy1();

	int level;
	int levelLoadCornudo;

	bool gameOver;
	bool pause;
	bool loseLife;
	int tick_gameOver_pause_loseLife;
	int numModels;

	
	void MenuOptions();


};
